package com.hksj.app.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FileTypeUtils {
    private static final String REGEX_IMAGE = "(?i).+\\.(jpg|jpeg|png|gif|bmp|glb|webp|tif|svg)$";
    private static final String REGEX_DOCUMENT = "(?i).+\\.(doc|docx|xls|xlsx|ppt|pptx|pdf)$";
    private static final String REGEX_MEDIA = "(?i).+\\.(mp4|avi|wmv|flv|rmvb)$";
    private static final String REGEX_AUDIO = "(?i).+\\.(mp3|wav)$";

    public static boolean isImage(String fileName) {
        return match(REGEX_IMAGE, fileName);
    }

    public static boolean isDocument(String fileName) {
        return match(REGEX_DOCUMENT, fileName);
    }

    public static boolean isMedia(String fileName) {
        return match(REGEX_MEDIA, fileName);
    }

    public static boolean isAudio(String fileName) {
        return match(REGEX_AUDIO, fileName);
    }

    private static boolean match(String regex, String str) {
        if (str == null) {
            return false;
        }
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }
}